package com.easybuilder.blog.controller;

import com.alibaba.fastjson.JSONObject;
import com.easybuilder.blog.entity.BlogLikes;
import com.easybuilder.blog.service.LikesService;
import com.easybuilder.common.base.controller.BaseController;
import com.easybuilder.common.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/likes")
public class LikesController extends BaseController {

    @Autowired
    private LikesService likesService;

    /** 点赞或回踩 */
    @PostMapping("/like")
    public Object like(@RequestBody BlogLikes likes) {
        log.info("点赞传参：{}", JSONObject.toJSONString(likes));
        if (null == likes || null == likes.getArticleId() || null == likes.getStatus() || null == likes.getType()) {
            return Error("服务繁忙");
        }
        Map<String, Integer> map = likesService.like(likes);
        return OK(map);
    }

}
